import 'package:flutter_test/flutter_test.dart';
import 'package:receive_sharing_intent_ohos/receive_sharing_intent_ohos.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  group('ReceiveSharingIntent', () {
    test('getInitialMedia should return a list of SharedMediaFile', () async {
      final mockInitialMedia = <SharedMediaFile>[
        SharedMediaFile(
          uri: 'test_uri_1',
          title: 'test_title_1',
          label: 'test_label_1',
          description: 'test_description_1',
          utd: 'test_utd_1',
          content: 'test_content_1',
        ),
      ];
      ReceiveSharingIntent.setMockValues(
        initialMedia: mockInitialMedia,
        mediaStream: Stream.value([]),
      );
      final result = await ReceiveSharingIntent.instance.getInitialMedia();
      expect(result, isA<List<SharedMediaFile>>());
      expect(result.length, 1);
      expect(result.first.uri, 'test_uri_1');
    });

    test('getMediaStream should return a Stream of SharedMediaFile', () {
      final mockMediaStream = Stream.value(<SharedMediaFile>[
        SharedMediaFile(
          uri: 'test_uri_2',
          title: 'test_title_2',
          label: 'test_label_2',
          description: 'test_description_2',
          utd: 'test_utd_2',
          content: 'test_content_2',
        ),
      ]);
      ReceiveSharingIntent.setMockValues(
        initialMedia: [],
        mediaStream: mockMediaStream,
      );
      final stream = ReceiveSharingIntent.instance.getMediaStream();
      stream.listen((mediaFiles) {
        expect(mediaFiles, isA<List<SharedMediaFile>>());
        expect(mediaFiles.length, 1);
        expect(mediaFiles.first.uri, 'test_uri_2');
      });
    });

    test('reset should return a Future', () async {
      ReceiveSharingIntent.setMockValues(
        initialMedia: [],
        mediaStream: Stream.value([]),
      );
      final result = await ReceiveSharingIntent.instance.reset();
      expect(result, null);
    });
  });

  group('SharedMediaFile', () {
    test('fromMap should create a valid SharedMediaFile object', () {
      final map = {
        'uri': 'test_uri',
        'title': 'test_title',
        'label': 'test_label',
        'description': 'test_description',
        'utd': 'test_utd',
        'content': 'test_content',
      };
      final sharedMediaFile = SharedMediaFile.fromMap(map);
      expect(sharedMediaFile, isA<SharedMediaFile>());
      expect(sharedMediaFile.uri, 'test_uri');
      expect(sharedMediaFile.title, 'test_title');
      expect(sharedMediaFile.label, 'test_label');
      expect(sharedMediaFile.description, 'test_description');
      expect(sharedMediaFile.utd, 'test_utd');
      expect(sharedMediaFile.content, 'test_content');
    });

    test('toMap should return a map representation of SharedMediaFile', () {
      final sharedMediaFile = SharedMediaFile(
        uri: 'test_uri',
        title: 'test_title',
        label: 'test_label',
        description: 'test_description',
        utd: 'test_utd',
        content: 'test_content',
      );
      final map = sharedMediaFile.toMap();
      expect(map, isA<Map<String, dynamic>>());
      expect(map['uri'], 'test_uri');
      expect(map['title'], 'test_title');
      expect(map['label'], 'test_label');
      expect(map['description'], 'test_description');
      expect(map['utd'], 'test_utd');
      expect(map['content'], 'test_content');
    });
  });
}